﻿using Microsoft.EntityFrameworkCore;
using MySqlStudent.UI.Infrastructure;
using MySqlStudent.UI.Models;

namespace MySqlStudent.UI
{
    public partial class ef_mysql_demoContext : DbContext
    {
        public ef_mysql_demoContext()
        {
        }

        public ef_mysql_demoContext(DbContextOptions<ef_mysql_demoContext> options)
            : base(options)
        {
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                optionsBuilder.UseMySql("server=localhost;database=ef_mysql_demo;user=root;password=123456;treattinyasboolean=true", Microsoft.EntityFrameworkCore.ServerVersion.FromString("8.0.22-mysql"));
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            // 指定实体在数据库中生成的名称
            modelBuilder.Seed();
        }

        //partial void OnModelCreatingPartial(ModelBuilder modelBuilder);

        public DbSet<Student> Students { get; set; }
        public DbSet<Course> Courses { get; set; }
        public DbSet<StudentCourse> StudentCourses { get; set; } // 中间表
    }
}